
import { saveAs } from 'file-saver';

export const saveWorkspace = async(matlab) => {
  const variable = matlab.variableArray;
  try {
    const blob = new Blob([JSON.stringify(variable, null, '\t')]);
    saveAs(blob, 'test.json');
  } catch (err) {
    console.error(err);
  }
  // try {
  //   const fileSystemFileHandle = await window.showSaveFilePicker({
  //     suggestedName: 'variable.json',
  //     types: [
  //       {
  //         description: 'Json',
  //         accept: {
  //           'application/json': '.json'
  //         }
  //       }
  //     ]
  //   });
  //   const writable = await fileSystemFileHandle.createWritable();
  //   await writable.write(JSON.stringify(variable, null, '\t'));
  //   await writable.close();
  //   this.$message.success('变量保存成功');
  // } catch (e) {
  //   console.log(e);
  // }
};
